package com.example.ktpspringboot.config;

import com.example.ktpspringboot.utils.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")  // 其他接口需要token验证
                //排除knife4j的接口文档页面
                .excludePathPatterns("/**.html")
                .excludePathPatterns("/v3/api-docs/**")
                //排除登录注册页面
                .excludePathPatterns("/login")
                .excludePathPatterns("/registerTeacher")
                .excludePathPatterns("/registerStudent");
    }

}
